package data;

import java.util.ArrayList;

public class ReportGenerator {

	public static void printReport(AReport inputReport) {
		int counter = 0;
		for (ARecord curRecord: inputReport.records) {
			System.out.println(counter++);
			System.out.println(curRecord.person);
			System.out.println(curRecord.project);
			System.out.println(curRecord.totalTime);
		}
		
	}
	
	public static AReport generateAReport(TaskList taskList) {
		AReport returnReport = new AReport();
		returnReport.records = new ArrayList<ARecord>();
		
		ArrayList<Person> personList = ListOperator.getPersonList(taskList.getTaskList());
		
		for(Person person : personList) {
			
			ArrayList<Task> personalTaskList = ListOperator.filterListByPerson(person, taskList.getTaskList());
			ArrayList<Project> personalProjectList = ListOperator.getProjectList(personalTaskList);
			for (Project project: personalProjectList) {
				ARecord currentRecord = new ARecord();
				currentRecord.person = person;
				currentRecord.project = project;
				currentRecord.totalTime = 0.0f;
				ArrayList<Task> personalProjectTaskList = ListOperator.filterListByProject(project, personalTaskList);
				for (Task task : personalProjectTaskList) {
					currentRecord.totalTime+=task.getTime();
				}
				returnReport.records.add(currentRecord);
			}
		}
		printReport(returnReport);
		return returnReport;	
	}
	
	public static BReport generateBReport(TaskList taskList) {
		BReport returnReport = new BReport();
		returnReport.records = new ArrayList<BRecord>();
		
		ArrayList<Project> projectList = ListOperator.getProjectList(taskList.getTaskList());
		
		for(Project project : projectList) {
			
			ArrayList<Task> projectTaskList = ListOperator.filterListByProject(project, taskList.getTaskList());
			ArrayList<Person> projectPersonalList = ListOperator.getPersonList(projectTaskList);
			for (Person person: projectPersonalList) {
				BRecord currentRecord = new BRecord();
				currentRecord.person = person;
				currentRecord.project = project;
				currentRecord.totalTime = 0.0f;
				ArrayList<Task> projectPersonalTaskList = ListOperator.filterListByPerson(person, projectTaskList);
				for (Task task : projectPersonalTaskList) {
					currentRecord.totalTime+=task.getTime();
				}
				returnReport.records.add(currentRecord);
			}
		}
		return returnReport;	
	}
	
	
}

